﻿//-----------------------------------------------------------------------
// <copyright>
//     Copyright (c) Artur Mustafin. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System;
using Excel.Expressions.Compiler;
using Expressions.Compiler;
using Expressions.Compiler.Interfaces;

namespace Excel.Expressions
{
    internal partial class Nonterminals
    {
        private static Rules<char> _cell_function_definition()
        {
            return new Rules<char>()
            {
                () => cell_function_name[false] + '(' + cell_function_arg_list[false] + ')'
            };
        }
    }

    internal partial class Expressions
    {
        private static Func<CellExpression, IExpressionTree<char>, CellExpression> _cell_function_definition()
        {
            return (a, b) =>
            {
                if (b[0].Context.Token.Equals(Nonterminals.cell_function_name) && b[1].Context.Token.Equals('(') && b[2].Context.Token.Equals(Nonterminals.cell_function_arg_list) && b[3].Context.Token.Equals(')'))
                {
                    return new Function(b[0].Context.ToString(), cell_function_arg_list[a, b[2]]);
                }
                throw new NotSupportedException("Input token is not supported");
            };
        }
    }
}
